package com.myfum.mobile.tetris.data.shapes
{
	import com.myfum.mobile.tetris.Config;
	import com.myfum.mobile.tetris.data.cubes.DropingCubeData;
	import com.myfum.mobile.tetris.interfaces.IShape;

	public class ShapeFactory
	{
		public static function createShape(type:int):IShape{
			var shape:IShape;
			switch(type){
				case ShapeType.I:
					shape = getIShape();
					break;
				case ShapeType.O:
					shape = getOShape();
					break;
				case ShapeType.SLEFT:
					shape = getSLeftShape();
					break;
				case ShapeType.SRIGHT:
					shape = getSRightShape();
					break;
				case ShapeType.LLEFT:
					shape = getLLeftShape();
					break;
				case ShapeType.LRIGHT:
					shape = getLRightShape();
					break;
				case ShapeType.T:
					shape = getTShape();
					break;
			}
			return shape;
		}
		
		public static function createRandomShape():IShape{
			return createShape(ShapeType.getRandomType());
		}
		
		private static function getIShape():IShape{
			var shape:IShapeData = new IShapeData();
			shape.cubes = new Vector.<DropingCubeData>();
			for(var i:int = 0;i<4;i++){
				var c:DropingCubeData = new DropingCubeData(3+i, 0, Config.default_cube);
				shape.cubes.push(c);
			}
			shape.skin = Config.default_cube;
			return shape;
		}
		
		private static function getOShape():IShape{
			var shape:OShapeData = new OShapeData();
			shape.cubes = new Vector.<DropingCubeData>();
			for(var i:int = 0;i<4;i++){
				var c:DropingCubeData = new DropingCubeData(4+i%2, int(i/2), Config.default_cube);
				shape.cubes.push(c);
			}
			shape.skin = Config.default_cube;
			return shape;
		}
		
		private static function getSLeftShape():IShape{
			var shape:SLeftShapeData = new SLeftShapeData();
			shape.cubes = new Vector.<DropingCubeData>();
			for(var i:int = 0;i<4;i++){
				var c:DropingCubeData = new DropingCubeData(0, 0, Config.default_cube);
				shape.cubes.push(c);
			}
			shape.cubes[0].x = 3;
			shape.cubes[0].y = 0;
			shape.cubes[1].x = 4;
			shape.cubes[1].y = 0;
			shape.cubes[2].x = 4;
			shape.cubes[2].y = 1;
			shape.cubes[3].x = 5;
			shape.cubes[3].y = 1;
			shape.skin = Config.default_cube;
			return shape;
		}
		
		private static function getSRightShape():IShape{
			var shape:SRightShapeData = new SRightShapeData();
			shape.cubes = new Vector.<DropingCubeData>();
			for(var i:int = 0;i<4;i++){
				var c:DropingCubeData = new DropingCubeData(0, 0, Config.default_cube);
				shape.cubes.push(c);
			}
			shape.cubes[0].x = 3;
			shape.cubes[0].y = 1;
			shape.cubes[1].x = 4;
			shape.cubes[1].y = 1;
			shape.cubes[2].x = 4;
			shape.cubes[2].y = 0;
			shape.cubes[3].x = 5;
			shape.cubes[3].y = 0;
			shape.skin = Config.default_cube;
			return shape;
		}
		
		private static function getLLeftShape():IShape{
			var shape:LLeftShapeData = new LLeftShapeData();
			shape.cubes = new Vector.<DropingCubeData>();
			for(var i:int = 0;i<4;i++){
				var c:DropingCubeData = new DropingCubeData(0, 0, Config.default_cube);
				shape.cubes.push(c);
			}
			shape.cubes[0].x = 3;
			shape.cubes[0].y = 0;
			shape.cubes[1].x = 3;
			shape.cubes[1].y = 1;
			shape.cubes[2].x = 4;
			shape.cubes[2].y = 1;
			shape.cubes[3].x = 5;
			shape.cubes[3].y = 1;
			shape.skin = Config.default_cube;
			return shape;
		}
		
		private static function getLRightShape():IShape{
			var shape:LRightShapeData = new LRightShapeData();
			shape.cubes = new Vector.<DropingCubeData>();
			for(var i:int = 0;i<4;i++){
				var c:DropingCubeData = new DropingCubeData(0, 0, Config.default_cube);
				shape.cubes.push(c);
			}
			shape.cubes[0].x = 3;
			shape.cubes[0].y = 1;
			shape.cubes[1].x = 4;
			shape.cubes[1].y = 1;
			shape.cubes[2].x = 5;
			shape.cubes[2].y = 1;
			shape.cubes[3].x = 5;
			shape.cubes[3].y = 0;
			shape.skin = Config.default_cube;
			return shape;
		}
		
		private static function getTShape():IShape{
			var shape:TShapeData = new TShapeData();
			shape.cubes = new Vector.<DropingCubeData>();
			for(var i:int = 0;i<4;i++){
				var c:DropingCubeData = new DropingCubeData(0, 0, Config.default_cube);
				shape.cubes.push(c);
			}
			shape.cubes[0].x = 3;
			shape.cubes[0].y = 1;
			shape.cubes[1].x = 4;
			shape.cubes[1].y = 1;
			shape.cubes[2].x = 5;
			shape.cubes[2].y = 1;
			shape.cubes[3].x = 4;
			shape.cubes[3].y = 0;
			shape.skin = Config.default_cube;
			return shape;
		}
	}
}